﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.BL;
using VINETLIFE.DO;

namespace VINETLIFE.AdminCP
{
    public partial class ListCategory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["Type"]))
            {
                int type = int.Parse(Request.QueryString["Type"]);
                // Content
                if (type == 1)
                {
                    tlCategory.DataSource = new cmsCategoryBL().SelectAdmin(true);
                    lblTitle.Text = "Danh mục nội dung";
                }
                //tin tuc
                else if (type == 0)
                {
                    tlCategory.DataSource = new cmsCategoryBL().SelectAdmin(false);
                    lblTitle.Text = "Danh mục tin tức";
                }
                tlCategory.DataBind();
                tlCategory.ExpandToLevel(3);
            }

        }

        protected void tlCategory_StartNodeEditing(object sender, DevExpress.Web.ASPxTreeList.TreeListNodeEditingEventArgs e)
        {
            int id = 0;
            if (int.TryParse(tlCategory.EditingNodeKey, out id))
            {
                Response.Redirect("Category.aspx?CategoryID=" + id.ToString());
            }
        }

        protected void tlCategory_NodeDeleted(object sender, DevExpress.Web.Data.ASPxDataDeletedEventArgs e)
        {
            new cmsCategoryBL().Delete(new cmsCategoryDO() { CategoryID = int.Parse(tlCategory.FocusedNode.Key) });
            Response.Redirect(Request.Url.ToString());
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("Category.aspx");
        }
    }
}